home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Table / Sources / Commands.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  23.7 KB  |  748 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Commands.cpp
  4. //    Release Version:    $ ODF 2 $ 
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef COMMANDS_H
  11. #include "Commands.h"
  12. #endif
  13.  
  14. #ifndef FRAME_H
  15. #include "Frame.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef SELECTION_H
  23. #include "Selection.h"
  24. #endif
  25.  
  26. #ifndef PROXY_H
  27. #include "Proxy.h"
  28. #endif
  29.  
  30. #ifndef LINKING_H
  31. #include "Linking.h"
  32. #endif
  33.  
  34. #ifndef CONTENT_H
  35. #include "Content.h"
  36. #endif
  37.  
  38. // ----- Framework Includes -----
  39.  
  40. #ifndef FWPART_H
  41. #include "FWPart.h"
  42. #endif
  43.  
  44. #ifndef FWFRAME_H
  45. #include "FWFrame.h"
  46. #endif
  47.  
  48. #ifndef FWSELECT_H
  49. #include "FWSelect.h"
  50. #endif
  51.  
  52. #ifndef FWBARRAY_H
  53. #include "FWBArray.h"
  54. #endif
  55.  
  56. #ifndef FWFRMING_H
  57. #include "FWFrming.h"
  58. #endif
  59.  
  60. #ifndef FWLNKMGR_H
  61. #include "FWLnkMgr.h"
  62. #endif
  63.  
  64. #ifndef FWSESION_H
  65. #include "FWSesion.h"
  66. #endif
  67.  
  68. #ifndef FWINTER_H
  69. #include "FWInter.h"
  70. #endif
  71.  
  72. // ----- OpenDoc Includes -----
  73.  
  74. #ifndef SOM_Module_OpenDoc_Commands_defined
  75. #include <CmdDefs.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODDragAndDrop_xh
  79. #include <DragDrp.xh>
  80. #endif
  81.  
  82. //========================================================================================
  83. //    Runtime Info
  84. //========================================================================================
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment odfTable
  88. #endif
  89.  
  90. FW_DEFINE_AUTO(CCellDragCommand)
  91. FW_DEFINE_AUTO(CCellDropCommand)
  92. FW_DEFINE_AUTO(CTableEditCommand)
  93. FW_DEFINE_AUTO(CTableInsertCommand)
  94.  
  95. //========================================================================================
  96. //    class CCellDragCommand
  97. //========================================================================================
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    CCellDragCommand constructor
  101. //----------------------------------------------------------------------------------------
  102.  
  103. CCellDragCommand::CCellDragCommand(    Environment* ev,
  104.                                     CTablePartContent* tableContent,
  105.                                     FW_CFrame* frame,
  106.                                     CTableSelection* selection) : 
  107.     FW_CDragCommand(ev, frame, FW_kCanUndo),
  108.     fTableContent(tableContent),
  109.     fTableSelection(selection),
  110.     fSavedProxy(NULL)
  111. {
  112.     fDragCell = selection->GetSelectedCell();
  113.     FW_END_CONSTRUCTOR
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    CCellDragCommand destructor
  118. //----------------------------------------------------------------------------------------
  119.  
  120. CCellDragCommand::~CCellDragCommand()
  121. {
  122.     FW_START_DESTRUCTOR
  123. }
  124.  
  125. //---------------------------------------------------------------------------------------
  126. //    CCellDragCommand::UndoIt
  127. //---------------------------------------------------------------------------------------
  128. void CCellDragCommand::UndoIt(Environment* ev)
  129. {
  130.     FW_ASSERT(fSavedProxy);
  131.  
  132.     // Restore saved proxy to the table
  133.     fSavedProxy->AttachEmbeddedFrames(ev);
  134.     fTableContent->AddProxy(fSavedProxy);
  135.     fTableSelection->SelectProxy(ev, fSavedProxy);
  136. }
  137.  
  138. //---------------------------------------------------------------------------------------
  139. //    CCellDragCommand::RedoIt
  140. //---------------------------------------------------------------------------------------
  141. void CCellDragCommand::RedoIt(Environment* ev)
  142. {
  143.     // Remove saved proxy, again
  144.     fTableSelection->SelectProxy(ev, fSavedProxy);
  145.     fTableSelection->ClearSelection(ev);
  146. }
  147.  
  148. //---------------------------------------------------------------------------------------
  149. //    CCellDragCommand::SaveUndoState
  150. //---------------------------------------------------------------------------------------
  151. void CCellDragCommand::SaveUndoState(Environment* ev)
  152. {
  153. FW_UNUSED(ev);
  154.     // Save the proxy for the part that was dragged
  155.     fSavedProxy = fTableContent->CellToProxy(fDragCell);
  156. }
  157.  
  158. //---------------------------------------------------------------------------------------
  159. //    CCellDragCommand::FreeUndoState
  160. //---------------------------------------------------------------------------------------
  161. void CCellDragCommand::FreeUndoState(Environment* ev)
  162. {
  163. FW_UNUSED(ev);
  164.     FW_ASSERT(fSavedProxy);
  165.     
  166.     delete fSavedProxy;
  167.     fSavedProxy = NULL;
  168. }
  169.  
  170. //========================================================================================
  171. //    class CCellDropCommand
  172. //========================================================================================
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    CCellDropCommand constructor
  176. //----------------------------------------------------------------------------------------
  177.  
  178. CCellDropCommand::CCellDropCommand(    Environment* ev,
  179.                                     CTablePart* itsPart,
  180.                                     CTablePartContent* tableContent,
  181.                                     CTableFrame* frame,
  182.                                     ODDragItemIterator* dropInfo, 
  183.                                     ODFacet* odFacet,
  184.                                     const FW_CPoint& dropPoint,
  185.                                     const CCell& dropCell,
  186.                                     const CCell& draggedCell) : 
  187.     FW_CDropCommand(ev, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
  188.     fTablePart(itsPart),
  189.     fTableContent(tableContent),
  190.     fTableFrame(frame),
  191.     fDropCell(dropCell),
  192.     fDraggedCell(draggedCell),
  193.     fSavedProxy(NULL),
  194.     fLinkCreated(false)
  195. {
  196.     // If this was a Cmd-drag, set the selection to the dropCell for DoDroppedPasteAs
  197.     ODDragAndDrop* drag = FW_CSession::GetDragAndDrop(ev);
  198.     unsigned long attributes = drag->GetDragAttributes(ev);
  199.     if (attributes & kODDropIsPasteAs)
  200.         fTableFrame->SelectCell(ev, fDropCell);
  201.  
  202.     FW_END_CONSTRUCTOR
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    CCellDropCommand destructor
  207. //----------------------------------------------------------------------------------------
  208.  
  209. CCellDropCommand::~CCellDropCommand()
  210. {
  211.     FW_START_DESTRUCTOR
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // CCellDropCommand::DoDrop
  216. //----------------------------------------------------------------------------------------
  217.  
  218. FW_Boolean CCellDropCommand::DoDrop(Environment* ev, 
  219.                                     ODStorageUnit* dropSU, 
  220.                                     const FW_CPoint& mouseDownOffset,
  221.                                     const FW_CPoint& dropPoint,
  222.                                     FW_Boolean isDropMove,
  223.                                     short itemNumber)
  224. {
  225.     if (itemNumber > 1)        // can only drop one item in a cell
  226.         return false;
  227.  
  228.     fTableFrame->SelectCell(ev, fDropCell);
  229.     
  230.     return FW_CDropCommand::DoDrop(ev, dropSU, mouseDownOffset, dropPoint, isDropMove, itemNumber);
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. // CCellDropCommand::DoDroppedInSameFrame
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_Boolean CCellDropCommand::DoDroppedInSameFrame(Environment* ev, 
  238.                                                   ODStorageUnit* dropSU, 
  239.                                                   const FW_CPoint& mouseDownOffset, 
  240.                                                   const FW_CPoint& dropPoint)
  241. {
  242.     FW_UNUSED(dropSU);
  243.     FW_UNUSED(mouseDownOffset);
  244.     FW_UNUSED(dropPoint);
  245.     
  246.     FW_ASSERT(fDropCell != fDraggedCell);
  247.     
  248.     // Move the frame's cell
  249.     
  250.     CTableProxy* proxy = fTableContent->CellToProxy(fDraggedCell);
  251.     FW_ASSERT(proxy);
  252.  
  253.     fTableFrame->MoveProxy(ev, proxy, fDropCell);
  254.     fTablePart->ProxyMoved(ev, fDraggedCell, fDropCell);
  255.  
  256.     return TRUE;
  257. }
  258.  
  259. //---------------------------------------------------------------------------------------
  260. //    CCellDropCommand::DoDroppedPasteAs
  261. //---------------------------------------------------------------------------------------
  262. void CCellDropCommand::DoDroppedPasteAs(Environment* ev, 
  263.                                         const FW_CPoint& mouseDownOffset, 
  264.                                         const FW_CPoint& dropPoint)
  265. {
  266.     FW_UNUSED(mouseDownOffset);
  267.     FW_UNUSED(dropPoint);
  268.  
  269.     // Remember whether a link was created
  270.     fLinkCreated = (GetNewLink(ev) != NULL);
  271. }
  272.  
  273. //---------------------------------------------------------------------------------------
  274. //    CCellDropCommand::UndoIt
  275. //---------------------------------------------------------------------------------------
  276. void CCellDropCommand::UndoIt(Environment* ev)
  277. {
  278.     // activate a table frame (the dropped part may be active)
  279.     CTableFrame* tableFrame = fTablePart->FindValidTableFrame(ev, fTableFrame, (CTableFrame*) GetSourceFrame(ev));
  280.     FW_ASSERT(tableFrame);
  281.     tableFrame->ActivateFrame(ev, NULL);
  282.  
  283.     if (this->IsDragMoveInSameFrame(ev))    // simple move from one cell to another
  284.     {
  285.         // move the dropped part back to the cell it came from
  286.         tableFrame->MoveProxy(ev, fSavedProxy, fDraggedCell);
  287.         fTablePart->ProxyMoved(ev, fDropCell, fDraggedCell);
  288.     }
  289.     else    // part was dropped here from outside
  290.     {
  291.         if (fLinkCreated)            // a link was created
  292.         {
  293.             // with links, proxy did not exist yet when command was 'done', and may
  294.             // change between redoing and undoing. Get it from the cell now.
  295.             
  296.             fSavedProxy = fTableContent->CellToProxy(fDropCell);
  297.         }
  298.         
  299.         // remove the dropped cell from the table
  300.         CTableSelection* selection = tableFrame->GetSelection(ev);
  301.         selection->SelectProxy(ev, fSavedProxy);
  302.         selection->ClearSelection(ev);
  303.     }
  304. }
  305.  
  306. //---------------------------------------------------------------------------------------
  307. //    CCellDropCommand::RedoIt
  308. //---------------------------------------------------------------------------------------
  309. void CCellDropCommand::RedoIt(Environment* ev)
  310. {
  311.     // use a valid frame
  312.     CTableFrame* tableFrame = fTablePart->FindValidTableFrame(ev, fTableFrame, (CTableFrame*) GetSourceFrame(ev));
  313.     FW_ASSERT(tableFrame);
  314.  
  315.     if (this->IsDragMoveInSameFrame(ev))    // simple move from one cell to another
  316.     {
  317.         // move the dropped part to the cell it was dropped in
  318.         tableFrame->MoveProxy(ev, fSavedProxy, fDropCell);
  319.         fTablePart->ProxyMoved(ev, fDraggedCell, fDropCell);
  320.     }
  321.     else    // part was dropped here from outside
  322.     {
  323.         // re-drop the cell
  324.         fSavedProxy->AttachEmbeddedFrames(ev);
  325.         fTableContent->AddProxy(fSavedProxy);
  326.         tableFrame->SelectCell(ev, fDropCell);
  327.         fTablePart->GetTableSelection(ev)->InvalidateSelection(ev);
  328.     }
  329. }
  330.  
  331. //---------------------------------------------------------------------------------------
  332. //    CCellDropCommand::SaveRedoState
  333. //---------------------------------------------------------------------------------------
  334. void CCellDropCommand::SaveRedoState(Environment* ev)
  335. {
  336. FW_UNUSED(ev);
  337.     if (!fLinkCreated)
  338.     {
  339.         // Save the proxy for the part that was just dropped
  340.         fSavedProxy = fTableContent->CellToProxy(fDropCell);
  341.     }
  342. }
  343.  
  344. //---------------------------------------------------------------------------------------
  345. //    CCellDropCommand::FreeRedoState
  346. //---------------------------------------------------------------------------------------
  347. void CCellDropCommand::FreeRedoState(Environment* ev)
  348. {
  349. FW_UNUSED(ev);
  350.     // Delete the saved proxy
  351.     delete fSavedProxy;
  352. }
  353.  
  354. //========================================================================================
  355. // CTableEditCommand class
  356. //========================================================================================
  357.  
  358. //---------------------------------------------------------------------------------------
  359. // CTableEditCommand constructor
  360. //---------------------------------------------------------------------------------------
  361. CTableEditCommand::CTableEditCommand(Environment* ev,
  362.                                      ODCommandID id,
  363.                                      CTablePart* itsPart, 
  364.                                      CTablePartContent* tableContent,
  365.                                      FW_CFrame* frame, 
  366.                                      CTableSelection* selection) :
  367.     FW_CClipboardCommand(ev, id, frame, FW_kCanUndo),
  368.     fTablePart(itsPart),
  369.     fTableContent(tableContent),
  370.     fTableSelection(selection),
  371.     fSavedProxy(NULL),
  372.     fSavedLinkSource(NULL),
  373.     fSavedLink(NULL)
  374. {
  375.     FW_END_CONSTRUCTOR
  376. }
  377.  
  378. //---------------------------------------------------------------------------------------
  379. // CTableEditCommand destructor
  380. //---------------------------------------------------------------------------------------
  381. CTableEditCommand::~CTableEditCommand()
  382. {
  383.     FW_START_DESTRUCTOR
  384. }
  385.  
  386. //---------------------------------------------------------------------------------------
  387. //    CTableEditCommand::UndoIt
  388. //---------------------------------------------------------------------------------------
  389. void CTableEditCommand::UndoIt(Environment* ev)
  390. {
  391.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  392.  
  393.     switch (GetCommandID(ev))
  394.     {
  395.         case kODCommandCut:
  396.         case kODCommandClear:
  397.             this->RestoreSelection(ev);
  398.             this->RestoreSavedLinks(ev);
  399.             break;
  400.  
  401.         case kODCommandPaste:
  402.             this->RemoveSelection(ev);
  403.             break;
  404.  
  405.         case kODCommandPasteAs:
  406.             this->UndoPasteAs(ev);
  407.     }    
  408. }
  409.  
  410. //---------------------------------------------------------------------------------------
  411. //    CTableEditCommand::RedoIt
  412. //---------------------------------------------------------------------------------------
  413. void CTableEditCommand::RedoIt(Environment* ev)    // Override
  414. {
  415.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  416.  
  417.     switch (GetCommandID(ev))
  418.     {
  419.         case kODCommandCut:
  420.         case kODCommandClear:
  421.             this->BreakSavedLinks(ev);    // do first, because next line causes UpdateLinkSource to be called
  422.             this->RemoveSelection(ev);
  423.             break;
  424.  
  425.         case kODCommandPaste:
  426.             this->RestoreSelection(ev);
  427.             break;
  428.  
  429.         case kODCommandPasteAs:
  430.             this->RedoPasteAs(ev);
  431.             break;    
  432.     }    
  433. }
  434.  
  435. //----------------------------------------------------------------------------------------
  436. //    CTableEditCommand::SaveUndoState
  437. //----------------------------------------------------------------------------------------
  438. void CTableEditCommand::SaveUndoState(Environment* ev)    // Override
  439. {
  440.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  441.     {
  442.         this->SaveSelection(ev);
  443.  
  444.         // If the saved proxy is a link source or destination, save the links too
  445.         CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
  446.         CCell cell = fSavedProxy->GetCell();
  447.         fSavedLink = linkMgr->CellToLink(ev, cell);
  448.         fSavedLinkSource = linkMgr->CellToSourceLink(ev, cell);
  449.     }
  450. }
  451.  
  452. //----------------------------------------------------------------------------------------
  453. //    CTableEditCommand::FreeUndoState (called by FW_CCommand::CommitDone)
  454. //----------------------------------------------------------------------------------------
  455. void CTableEditCommand::FreeUndoState(Environment* ev)    // Override
  456. {
  457.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  458.     {
  459.         this->DeleteSavedProxy(ev);
  460.         delete fSavedLink;
  461.         delete fSavedLinkSource;
  462.     }
  463. }
  464.  
  465. //----------------------------------------------------------------------------------------
  466. //    CTableEditCommand::SaveRedoState
  467. //----------------------------------------------------------------------------------------
  468. void CTableEditCommand::SaveRedoState(Environment* ev)    // Override
  469. {
  470.     if (GetCommandID(ev) == kODCommandPaste)
  471.     {
  472.         this->SaveSelection(ev);
  473.     }
  474.     else if (GetCommandID(ev) == kODCommandPasteAs)
  475.     {
  476.         // If a link was created don't save the proxy;
  477.         // a new proxy is created when the link is updated
  478.         if (!WasLinkCreated(ev))
  479.             this->SaveSelection(ev);
  480.     }
  481. }
  482.  
  483. //----------------------------------------------------------------------------------------
  484. //    CTableEditCommand::PreCommand
  485. //----------------------------------------------------------------------------------------
  486. void CTableEditCommand::PreCommand(Environment* ev)
  487. {
  488.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  489.     {
  490.         // See if there's a link spec on the clipboard for the selected item,
  491.         // and if so remove it.
  492.         FW_CLinkManager* linkMgr = fTablePart->GetLinkManager(ev);
  493.         FW_CLinkSource* linkSource = linkMgr->GetPendingClipboardLink(ev);
  494.         if (linkSource)
  495.         {    // clipboard does contain a link spec
  496.             if (linkSource->GetPendingID(ev) == fTableSelection->GetSavedLinkSpecID(ev))
  497.                 linkMgr->DeletePendingClipboardLink(ev);
  498.         }
  499.     }
  500. }
  501.  
  502. //----------------------------------------------------------------------------------------
  503. //    CTableEditCommand::CommandDone
  504. //----------------------------------------------------------------------------------------
  505. void CTableEditCommand::CommandDone(Environment* ev)
  506. {
  507.     if (GetCommandID(ev) == kODCommandPasteAs)
  508.     {
  509.         if (WasLinkCreated(ev))
  510.             fPasteAsCell = fTableSelection->GetSelectedCell();
  511.     }
  512.     else if (GetCommandID(ev) == kODCommandCopy)
  513.     {
  514.         // remember which proxy's link spec is on the clipboard
  515.         fTableSelection->SaveLinkSpecID(ev, fTablePart->GetDataInterchange(ev)->GetLastClipboardUpdateID(ev));
  516.     }
  517.     else if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  518.     {
  519.         // if the proxy that was cleared was in a link source or destination, break them
  520.         this->BreakSavedLinks(ev);
  521.     }
  522. }
  523.  
  524. //----------------------------------------------------------------------------------------
  525. //    CTableEditCommand::BreakSavedLinks
  526. //----------------------------------------------------------------------------------------
  527. void CTableEditCommand::BreakSavedLinks(Environment* ev)
  528. {
  529.     // If there are saved links (from SaveUndoState), break them
  530.     if (fSavedLink)
  531.     {
  532.         fTablePart->GetLinkManager(ev)->BreakDestinationLink(ev, fSavedLink);
  533.     }
  534.     if (fSavedLinkSource)
  535.     {
  536.         fTablePart->GetLinkManager(ev)->BreakSourceLink(ev, fSavedLinkSource);
  537.     }
  538. }
  539.  
  540. //----------------------------------------------------------------------------------------
  541. //    CTableEditCommand::RestoreSavedLinks
  542. //----------------------------------------------------------------------------------------
  543. void CTableEditCommand::RestoreSavedLinks(Environment* ev)
  544. {
  545.     // If there are saved links, restore them
  546.     if (fSavedLink)
  547.     {
  548.         fTablePart->GetLinkManager(ev)->RestoreDestinationLink(ev, fSavedLink);
  549.     }
  550.     if (fSavedLinkSource)
  551.     {
  552.         fTablePart->GetLinkManager(ev)->RestoreSourceLink(ev, fSavedLinkSource);
  553.     }
  554. }
  555.  
  556. //----------------------------------------------------------------------------------------
  557. //    CTableEditCommand::WasLinkCreated
  558. //----------------------------------------------------------------------------------------
  559. FW_Boolean CTableEditCommand::WasLinkCreated(Environment* ev)
  560. {
  561.     return (GetNewLink(ev) != NULL);
  562. }
  563.  
  564. //----------------------------------------------------------------------------------------
  565. //    CTableEditCommand::FreeRedoState (called by FW_CCommand::CommitUndone)
  566. //----------------------------------------------------------------------------------------
  567. void CTableEditCommand::FreeRedoState(Environment* ev)    // Override
  568. {
  569.     if (GetCommandID(ev) == kODCommandPaste || GetCommandID(ev) == kODCommandPasteAs)
  570.     {
  571.         this->DeleteSavedProxy(ev);
  572.     }
  573. }
  574.  
  575. //---------------------------------------------------------------------------------------
  576. //    CTableEditCommand::SaveSelection
  577. //---------------------------------------------------------------------------------------
  578. void CTableEditCommand::SaveSelection(Environment* ev)
  579. {
  580. FW_UNUSED(ev);
  581.     //--- The selection is a single embedded frame ---
  582.     CCell cell = fTableSelection->GetSelectedCell();            // selected cell
  583.     fSavedProxy = fTableContent->CellToProxy(cell);
  584. }
  585.  
  586. //---------------------------------------------------------------------------------------
  587. //    CTableEditCommand::RestoreSelection
  588. //---------------------------------------------------------------------------------------
  589.  
  590. void CTableEditCommand::RestoreSelection(Environment* ev)
  591. {
  592.     // Re-attach the proxy's frames
  593.     fSavedProxy->AttachEmbeddedFrames(ev);
  594.  
  595.     // Add the saved proxy back into the table part
  596.     fTableContent->AddProxy(fSavedProxy);
  597.  
  598.     // Select it
  599.     fTableSelection->CloseSelection(ev);
  600.     fTableSelection->SelectProxy(ev, fSavedProxy);
  601.     fTableSelection->InvalidateSelection(ev);
  602.  
  603. }
  604.  
  605. //---------------------------------------------------------------------------------------
  606. //    CTableEditCommand::RemoveSelection
  607. //---------------------------------------------------------------------------------------
  608. void CTableEditCommand::RemoveSelection(Environment* ev)
  609. {
  610.     // Make sure the saved proxy is selected
  611.     fTableSelection->CloseSelection(ev);
  612.     fTableSelection->SelectProxy(ev, fSavedProxy);
  613.  
  614.     // Save the selected proxy
  615.     this->SaveSelection(ev);
  616.     
  617.     // Clear the selection, which includes detaching the proxy frames.
  618.     fTableSelection->ClearSelection(ev);
  619. }
  620.  
  621. //---------------------------------------------------------------------------------------
  622. //    CTableEditCommand::DeleteSavedProxy
  623. //---------------------------------------------------------------------------------------
  624.  
  625. void CTableEditCommand::DeleteSavedProxy(Environment* ev)
  626. {
  627. FW_UNUSED(ev);
  628.  
  629.     FW_ASSERT(fSavedProxy);
  630.     
  631.     delete fSavedProxy;
  632.     fSavedProxy = NULL;
  633. }
  634.  
  635. //---------------------------------------------------------------------------------------
  636. // CTableEditCommand::UndoPasteAs
  637. //---------------------------------------------------------------------------------------
  638.  
  639. void CTableEditCommand::UndoPasteAs(Environment* ev)
  640. {
  641.     //--- Break the link, if there is one ---
  642.     if (WasLinkCreated(ev))
  643.     {
  644.         // with links, proxy did not exist yet when command was 'done', and may
  645.         // change between redoing and undoing get it from the cell now.
  646.         
  647.         fSavedProxy = fTableContent->CellToProxy(fPasteAsCell);
  648.     }
  649.     
  650.     // just like a normal Paste command
  651.     this->RemoveSelection(ev);
  652.  
  653.     //--- Force redraw ---
  654.     GetFrame(ev)->GetPresentation(ev)->Invalidate(ev);
  655.  
  656. }
  657.  
  658. //---------------------------------------------------------------------------------------
  659. // CTableEditCommand::RedoPasteAs
  660. //---------------------------------------------------------------------------------------
  661. void CTableEditCommand::RedoPasteAs(Environment* ev)
  662. {
  663.     this->RestoreSelection(ev);
  664. }
  665.  
  666. //========================================================================================
  667. // CTableInsertCommand class
  668. //========================================================================================
  669.  
  670. //---------------------------------------------------------------------------------------
  671. // CTableInsertCommand constructor
  672. //---------------------------------------------------------------------------------------
  673.  
  674. CTableInsertCommand::CTableInsertCommand(Environment* ev,
  675.                                          FW_CEmbeddingFrame* frame,
  676.                                          const FW_PFileSpecification& fileSpec,
  677.                                          CTablePart* itsPart,
  678.                                          const CCell& insertCell)
  679. :    FW_CInsertCommand(ev, frame, fileSpec, FW_kCanUndo),
  680.     fTablePart(itsPart),
  681.     fTableContent(NULL),
  682.     fInsertedProxy(NULL),
  683.     fInsertCell(insertCell)
  684. {
  685.     fTableContent = itsPart->GetTableContent(ev);
  686.     FW_END_CONSTRUCTOR
  687. }
  688.  
  689. //---------------------------------------------------------------------------------------
  690. // CTableInsertCommand destructor
  691. //---------------------------------------------------------------------------------------
  692.  
  693. CTableInsertCommand::~CTableInsertCommand()
  694. {
  695.     FW_START_DESTRUCTOR
  696. }
  697.  
  698. //---------------------------------------------------------------------------------------
  699. //    CTableInsertCommand::UndoIt
  700. //---------------------------------------------------------------------------------------
  701.  
  702. void CTableInsertCommand::UndoIt(Environment* ev)
  703. {
  704.     // activate a table frame (the inserted part may be active)
  705.     CTableFrame* tableFrame = fTablePart->FindValidTableFrame(ev, (CTableFrame*) GetFrame(ev), (CTableFrame*) GetSourceFrame(ev));
  706.     FW_ASSERT(tableFrame);
  707.     tableFrame->ActivateFrame(ev, NULL);
  708.  
  709.     // remove the inserted part
  710.     CTableSelection* selection = fTablePart->GetTableSelection(ev);
  711.     selection->Select(ev, fInsertCell);
  712.     selection->ClearSelection(ev);
  713. }
  714.  
  715. //---------------------------------------------------------------------------------------
  716. //    CTableInsertCommand::RedoIt
  717. //---------------------------------------------------------------------------------------
  718.  
  719. void CTableInsertCommand::RedoIt(Environment* ev)
  720. {
  721.     // re-insert the part
  722.     fInsertedProxy->AttachEmbeddedFrames(ev);
  723.     fTableContent->AddProxy(fInsertedProxy);
  724.     CTableSelection* selection = fTablePart->GetTableSelection(ev);
  725.     selection->Select(ev, fInsertCell);
  726.     selection->InvalidateSelection(ev);
  727. }
  728.  
  729. //---------------------------------------------------------------------------------------
  730. //    CTableInsertCommand::FreeRedoState
  731. //---------------------------------------------------------------------------------------
  732.  
  733. void CTableInsertCommand::FreeRedoState(Environment*)
  734. {
  735.     delete fInsertedProxy;
  736. }
  737.  
  738. //---------------------------------------------------------------------------------------
  739. //    CTableInsertCommand::SaveRedoState
  740. //---------------------------------------------------------------------------------------
  741.  
  742. void CTableInsertCommand::SaveRedoState(Environment*)
  743. {
  744.     fInsertedProxy = fTableContent->CellToProxy(fInsertCell);
  745. }
  746.  
  747.  
  748.